<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	//超时未支付订单取消
    $_SESSION['forward_url']='jy_formget/index/';
    model('core/core')->checklogin();
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$order_list=pdo_getslice('jy_formget_message',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($order_list){
		$minzus=$this->model('model')->minzus();
		$yibaotype=$this->model('model')->yibaotype();
		$shenfentype=$this->model('model')->shenfentype();
        $sex=array(1=>'男',2=>'女');
		foreach($order_list as &$item){
			$user=model('core/member')->detail($item['mid'],array('credit1','credit2','mobile','groupid','avatar','nickname'));
			$item['nickname']=$user['nickname'];
			$item['mobile']=$user['mobile'];
			$item['sex']=$sex[$item['sex']];
			$item['minz']=$minzus[$item['minz']];
			$item['createtime']=date('Y-m-d H:i:s', $item['createtime']);		
		}
	}
	$return['list']=$order_list;
	exi($return);
}
//订单详情
if($_RQ['op']=='detail'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择','error');
	}
	$item=pdo_get('jy_formget_message',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	//用户信息
	$member=model('core/member')->detail($item['uid'],array('credit1','credit2','mobile','groupid','avatar','nickname'));
	$item['nickname']=$user['nickname'];
	$item['mobile']=$user['mobile'];
	$item['sex']=$sex[$item['sex']];
	$item['minz']=$minzus[$item['minz']];
	$item['yibao']=$yibaotype[$item['yibao']];
	$item['shenfen']=$shenfentype[$item['shenfen']];
	$item['createtime']=date('Y-m-d H:i:s', $item['createtime']);	
	$return['order']=$item;
	$return['member']=$member;
	exi($return);
}
if($_RQ['op']=='del'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择订单','error');
	}
	pdo_delete('jy_formget_message',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	exi('删除预约成功');
}
if($_RQ['op']=='pay'){
	$id= intval($_RQ['id']);
	if(!$id){
		exi('表单不存在，请重新选择表单','error');
	}
	$pay_id=pdo_getcolumn('jy_formget_message',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id),'pay_id');
	exi($pay_id);
}
if($_RQ['op']=='post'){
	//$posttype=1,多表单提交
	$postdata=get_postdata();
	if(!$postdata['name']){
		exi('姓名不能为空!','error');
	}
	if(!$postdata['sex']){
		exi('性别不能为空!','error');
	}
	if(!$postdata['minz']){
		exi('请选择民族!','error');
	}
	if(!$postdata['age']){
		exi('请填写年龄!','error');
	}
	if(!$postdata['mobile']){
		exi('请填写联系电话!','error');
	}
    if(!$postdata['code']){
        exi('请填写身份证号!','error');
    }
    if(!$postdata['shenfen']){
        exi('请选择本人身份!','error');
    }
    if(!$postdata['peiname']){
        exi('请输入被陪护人姓名!','error');
    }
    if(!$postdata['chuangnum']){
        exi('请输入床位号','error');
    }
    if($postdata['code']){
	    $checkcode=$this->model('model')->checkcode($postdata['code']);
        if(!$checkcode) {
            exi('请填写正确的身份证!', 'error');
        }
    }
    if($postdata['mobile']){
        if(!preg_match("/^1[345678]{1}\d{9}$/",$postdata['mobile'])){
            exi('请输入正确的手机号码!','error');
        }
    }
    $daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$msglog = pdo_get('jy_formget_message',array('createtime >'=>$daytime,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	if(!empty($msglog)){
        //exi('您已经提交过了!','error');
	}
	$data=array(
		'name'=>$postdata['name'],
		'sex'=>$postdata['sex'],
		'minz'=>$postdata['minz'],
		'age'=>$postdata['age'],
		'code'=>$postdata['code'],
		'mobile'=>$postdata['mobile'],
		'address'=>$postdata['address'],
		'yibao'=>$postdata['yibao'],
		'shenfen'=>$postdata['shenfen'],
		'peiname'=>$postdata['peiname'],
        'chuangnum'=>$postdata['chuangnum'],
	);
	if(!$msglog['id']){
		$data['uniacid']=$_SESSION['uniacid'];
		$data['mid']=$_SESSION['uid'];
		$data['createtime']=TIMESTAMP;
		pdo_insert('jy_formget_message',$data);
		$order_id=pdo_insertid();
        exi('提交成功!','','/diyform/');
	}else{
		pdo_update('jy_formget_message',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$msglog['id']));
        exi('修改成功!','','/diyform/');
		exi($return);
	}
}
